#include "stdio.h"
#include "sys/types.h"
#include "sys/ioctl.h"
#include "stdlib.h"
#include "termios.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "sys/time.h"

#include <string.h>
#include <jni.h>
#include <android/log.h>



#define LOG_TAG "ARMJNI"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)


    int tempFD;
    unsigned char tempFuf[4];
    int bizhangFD;
    unsigned char bizhangFuf[1];
    int elecFD;
//temp
jint 
Java_com_xpfirst_arm_ARMJNI_openTemp( JNIEnv* env )
{
	tempFD=open("/dev/temp",O_RDWR | O_NDELAY | O_NOCTTY);
    	if (tempFD < 0) {
        	LOGI("Open Device DS18B20 failed.\r\n");
    	}
        else{
		LOGI("Open Device DS18B20 successed.\r\n");
	}
	return tempFD;
}
jstring
Java_com_xpfirst_arm_ARMJNI_ReadTemp( JNIEnv* env, jobject thiz)
{
    read(tempFD, tempFuf, sizeof(tempFuf));
     return (*env)->NewStringUTF(env, tempFuf);
}
//bizhang
jint 
Java_com_xpfirst_arm_ARMJNI_openBiZhang( JNIEnv* env )
{
    	bizhangFD = open("/dev/bizhang",O_RDWR);
    	if (bizhangFD < 0) {
        	LOGI("Open Device bizhang failed.\r\n");
    	}
        else{
		LOGI("Open Device bizhang successed.\r\n");
	}
	return bizhangFD;
}
jstring
Java_com_xpfirst_arm_ARMJNI_ReadBiZhang( JNIEnv* env, jobject thiz)
{
    read(bizhangFD, bizhangFuf, sizeof(bizhangFuf));
     return (*env)->NewStringUTF(env, bizhangFuf);
}
//elec
jint 
Java_com_xpfirst_arm_ARMJNI_openElec( JNIEnv* env, jobject thiz )
{
    	elecFD = open("/dev/elec", O_RDWR);
    	if (elecFD < 0) {
        	LOGI("openElec failed.\r\n");
    	}
        else{
		LOGI("openElec successed.\r\n");
	}
	return elecFD;
}
jint 
Java_com_xpfirst_arm_ARMJNI_ioctlElec( JNIEnv* env, jobject thiz,jint cmd,jint arg)
{
	jint io = ioctl(elecFD,cmd,arg);
	return io;
}
